<?php $weekending = strtotime($timesheet['Timesheet']['title']); ?>


<?php
$taskbyclient = array();
foreach($tasks as $task):
	$taskbyclient[$task['Task']['client_id']][$task['Task']['id']] = $task['Task'];
endforeach;
unset($tasks);

$usersbyclient = array();
foreach($users as $user):
	$usersbyclient[$user['User']['id']] = $user['User'];
endforeach;
unset($users);


/*echo '<pre>';
print_r($usersbyclient);
echo '</pre>';*/
?>

<h2>Timesheet for:<?php echo $usersbyclient[$timesheet['Timesheet']['user_id']]['username'] ?>, Week Ending: <?php echo date('F j, Y',$weekending) ?></h2>
<?php

echo $this->Form->create('Timesheet'); ?>
<table width="100%" border="0" cellspacing="1">
  <tr>
    <td>
    <?php
    $clientsbyclient = array();
    foreach($clients as $client):?>
        <?php $clientsbyclient[$client['Client']['id']] = $client['Client']; ?>
    <?php endforeach; ?>
    <?php unset($clients); ?>
    </td>
    <td></td>
    <td></td>
    <td></td>
    <td width="80"></td>
  </tr>
</table>

<table width="100%" border="0" cellspacing="1" class="table">
	<tr>
    <th>Client</th>
    
	<?php
	$oneday = 60*60*24;
	$days = 6;
	for($i = $days; $i>=0; $i--): ?>
	<th class="colum-thin"><?php 
	echo date('l', $weekending - $i*$oneday);
	echo '<br />';
	echo date('jS',$weekending - $i*$oneday); ?></th>
	<?php endfor; ?>
    
    <th class="colum-thin"TOTAL</th>
    </tr>
    
    <?php
	$content = json_decode($timesheet['Timesheet']['content']);
	
	foreach($content as $key => $item):
		if($key == 'total'){ ?>
			<tr>
              <td class="total">TOTAL<p></td>
              
              <?php 
			  $totalvalues = $item; 
			  foreach($totalvalues as $key => $totalvalue):?>
              	<td class="total"><?php echo $totalvalue; ?></td>
              <?php endforeach; ?>
              <?php unset($totalvalues); ?>
              
            </tr>
		<?php
        }else{ ?>
        	
        <?php
			$client = $item;
			/*echo '<pre>';
			print_r($client);
			echo '</pre>'; */?>
			<tr>
				<td colspan="9" class="client"><?php echo $clientsbyclient[$key]['title']; ?></td>
			</tr>
            
            <?php
			foreach($client as $taskkey => $task):?>
            	<tr class="column_client_<?php echo $key; ?> taskof_<?php echo $key; ?>" id="task_<?php echo $taskkey; ?>">
                    
                    <?php foreach($task as $day => $taskvalue):
						if($day == 'description'){?>
							<td class="task bullet">
                            	<?php echo $taskbyclient[$key][$taskkey]['title']; ?>
                                <p><?php echo $taskvalue; ?></p></td>
                        <?php
						}else{
							if($day == 'total'){?>
                    			<td ><?php echo $taskvalue; ?></td>
                             <?php
							}else{ ?>
                            	<td ><?php echo $taskvalue; ?></td>
                    	<?php 
							}
						} 
						?>
                    <?php endforeach; ?>
            		<?php unset($task); ?>
            	</tr>
                
			<?php endforeach; ?>
            <?php unset($client); ?>
            
        <?php
		}
    endforeach;
	unset($content);
	?>
</table>

